import 'package:flutter/material.dart';
import 'package:common/export/tools.dart';
import 'package:theme/colors.dart';

enum LaraPressTextType {
  // 导航栏标题
  appBarTitle,
  // 列表标题
  listTitle,
  // 列表副标题
  listSubTitle,
  // 列表内容
  listContent,
  // 列表元数据
  listMeta,
  // 内容标题
  contentTitle,
  // 内容副标题
  contentSubTitle,
  // 内容正文
  contentText,
  // 内容元数据
  contentMeta,
  // 详情标题
  detailTitle,
}

class LaraPressText extends StatelessWidget {
  final String text;
  final TextStyle? style;
  final LaraPressTextType type;
  final Color? color;
  final double? lineHeight;
  final int? maxLines;
  final FontWeight? fontWeight;
  const LaraPressText({
    super.key,
    this.text = "",
    this.type = LaraPressTextType.listContent,
    this.style,
    this.color,
    this.lineHeight,
    this.maxLines,
    this.fontWeight,
  });

  @override
  Widget build(BuildContext context) {
    TextStyle? style = this.style;
    if (style == null) {
      switch (type) {
        case LaraPressTextType.appBarTitle:
          style = style?.copyWith(fontSize: 16.sp, fontWeight: FontWeight.bold);
          break;
        case LaraPressTextType.contentText:
          style = style?.copyWith(fontSize: 14.sp, fontWeight: FontWeight.bold);
          break;
        case LaraPressTextType.listTitle:
          style = Theme.of(context).textTheme.titleMedium;
          break;
        case LaraPressTextType.detailTitle:
          style = Theme.of(context).textTheme.headlineLarge;
          break;
        case LaraPressTextType.listMeta:
          style = Theme.of(
            context,
          ).textTheme.bodySmall!.copyWith(color: LaraPressColors.listMeta);
          break;
        case LaraPressTextType.listContent:
          style = Theme.of(context).textTheme.bodyMedium!.copyWith(
            color: LaraPressColors.listContent,
            height: lineHeight ?? 1.8,
          );
          break;
        default:
      }
    }
    if (fontWeight != null) {
      style = style?.copyWith(fontWeight: fontWeight);
    }
    if (color != null) {
      style = style?.copyWith(color: color);
    }
    return Text(
      text,
      style: style,
      maxLines: maxLines,
      overflow: maxLines != null ? TextOverflow.ellipsis : null,
    );
  }
}

class LaraPressIcon extends StatelessWidget {
  final IconData icon;
  final double? size;
  final LaraPressTextType type;
  final Color? color;
  const LaraPressIcon({
    super.key,
    required this.icon,
    this.size,
    this.type = LaraPressTextType.listMeta,
    this.color,
  });
  @override
  Widget build(BuildContext context) {
    Color? userColor = color;
    if (userColor == null && type == LaraPressTextType.listMeta) {
      userColor = Theme.of(context).colorScheme.onSurfaceVariant;
    }
    return Icon(icon, size: size, color: userColor);
  }
}
